package com.kingja.sample.callback;

import com.kingja.loadsir.callback.Callback;
import com.kingja.sample.ResourceTable;
import ohos.agp.animation.Animator;
import ohos.agp.animation.AnimatorProperty;
import ohos.agp.animation.AnimatorValue;
import ohos.agp.components.Component;
import ohos.agp.components.RoundProgressBar;
import ohos.app.Context;

public class AnimateCallback extends Callback {
    @Override
    protected int onCreateView() {
        return ResourceTable.Layout_layout_animate;
    }

    private AnimatorProperty animator;

    private Component animatorView;

    @Override
    public void onAttach(Context context, Component view) {
        super.onAttach(context, view);

        animatorView = view.findComponentById(ResourceTable.Id_view_animate);

        animator = animatorView.createAnimatorProperty();
        animator.rotate(359).setDuration(1000).setLoopedCount(Integer.MAX_VALUE);
        animator.setCurveType(Animator.CurveType.ACCELERATE);
        animator.start();
    }

    @Override
    public void onDetach() {
        super.onDetach();
        if (animator != null) {
            animator.stop();
            animator = null;
        }
    }
}
